package edu.gdkm.dao;

import edu.gdkm.pojo.Orders;
import edu.gdkm.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersMapper {
    @Select("select * from tb_orders where user_id=#{id} ")
    @ResultMap("OrdersWithProductMap")
    List<Orders> selectOrdersByUserId(int user_id);
    @Select("select * from tb_orders where id=#{id} ")
    @Results(id = "OrdersWithProductMap",value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "id",
                    property = "productList",
                    many = @Many(select ="edu.gdkm.dao.ProductMapper.selectProductByOrdersId"))
    })
    Orders selectOrdersById(int id);
    @Select("select * from tb_orders where id in (select orders_id from " +
            "tb_ordersitem where product_id = #{id} )")
    List<Orders> selectOrdersByProductId(int product_id);
}
